package com.hnust.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnust.entity.dto.DeviceDto;
import com.hnust.entity.dto.DeviceSum;
import com.hnust.service.DeviceService;
import com.hnust.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建人：zhangRuWang
 * 创建时间：2022/4/9
 * 描述：设备管理
 */
@Slf4j
@RestController
@CrossOrigin("*")
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @GetMapping("/sum")
    public R<DeviceSum> deviceSum(){
        return R.success(deviceService.deviceSum());
    }

    @GetMapping("/search")
    public R<Page<DeviceDto>> deviceSearch(Integer pageSize,Integer page,
                                           String deviceType,String deviceName){
        log.info("调用搜索设备接口:pageSize:{},page:{},deviceType:{},deviceName:{}",
                pageSize,page,deviceType,deviceName);
        Page<DeviceDto> pageInfo= deviceService.deviceSearch(page,pageSize,deviceType,deviceName);
        return R.success(pageInfo);
    }

    @PostMapping("/modify")
    public R<String> deviceModify(@RequestBody DeviceDto deviceDto){
        log.info("修改设备{}",deviceDto);
        deviceService.deviceModify(deviceDto);
        return R.success("修改成功");
    }

    @PostMapping("/add")
    public R<String> deviceAdd(@RequestBody DeviceDto deviceDto){
        log.info("添加设备:{}",deviceDto);
        deviceService.deviceAdd(deviceDto);
        return R.success("添加成功");
    }
}
